<script setup lang="ts">
import { useRoute,useRouter } from 'vue-router';
import { ref } from 'vue';
const route =useRoute()
const router =useRouter()
const date = new Date()
const phone =ref('')
const name =ref('')
 const checked=ref(true)
const peoplenum =ref(1)
const year =date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const d = date.getDay()
const hour = date.getHours()+1
const min = date.getMinutes()
const sec = date.getSeconds()
const nday =(date.getDate()==30||(date.getMonth()==4&&6&&9&&11))&&(date.getDate()==31||(date.getMonth()==1&&3&&5&&7&&8&&10&&12))?1:date.getDate()+1
const nmonth =nday==1?date.getMonth() + 2:date.getMonth() + 1
const nd = date.getDay()+1
const price =Number(route.query.price)+200
function payinto(){

    const unpaly =ref(JSON.parse(localStorage.getItem("unpalys"))||[])
    console.log(unpaly);
    
    const arr={
        kind:  route.query.kind,
        bed:route.query.bed,
        img:route.query.img,
        year:year,
        month:month,
        day:day,
        hour:hour,
        min:min,
        sec:sec,
        price:route.query.price,
        proid:route.query.proid
    }
    console.log(unpaly.value);
    
    unpaly.value.push(arr)
    localStorage.setItem("unpalys",JSON.stringify(unpaly.value))
    console.log(unpaly.value);
    
    router.push(   {
     name: 'step2',
        query: {
       proid:route.query.proid,
       year:year,
       month:month,
       day:day,
       hour:hour,
       min:min,
       sec:sec,
       nmonth:nmonth,
       nday:nday,
       bed:  route.query.bed,
       kind:  route.query.kind,
       price:  route.query.price,
       start: route.query.start,
       img:route.query.img,
       phone:phone.value,
       name:name.value,
       nprice:price
        }
})
}
function numToChinese(num:number) {
    const chineseNumbers = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
    return chineseNumbers[num];
}
function jianClick(){
    peoplenum.value==1?peoplenum.value=1:peoplenum.value--
}
function addClick(){
    peoplenum.value==Number(route.query.bed)?peoplenum.value=Number(route.query.bed):peoplenum.value++
}
</script>
<template>
    <main class="box">
    <div class="content"> 
        <div  class="homecard">
<van-image class="cardimg" :src=String(route.query.img)   alt="" />
<div class="cardtitle">拱北华山别墅</div>
<div class="cardcontet">{{ route.query.kind }}· {{route.query.bed }}居{{ route.query.bed }}床{{ route.query.bed }}人·123平米</div>
<div class="Price">￥{{ route.query.price }}</div>
</div>
<div class="datecard">
<div class="leave">
<div class="datetitle">入离日期</div>

<div class="changedate"><span class="change">修改日期</span><van-icon size="20" name="arrow" /></div>
</div>
<div class="timebox">
<div class="timeleft">
<div class="start">{{ month }}月{{ day }}日</div>
<div class="timestart">周{{numToChinese(d)}}的{{ hour }}:00入住</div>
</div>
<div class="timemiddle">共一晚</div>
<div class="timeright">
    <div class="end">{{ nmonth }}月{{ nday }}日</div>
    <div class="timeend">周{{numToChinese(nd)}}的12:00前入住离开</div></div>
</div>
<div class="people"><div class="totalpeople">入住人数({{ peoplenum }}/{{ route.query.bed }})</div>
    <div class="addpeople"><span class="changepeople" @click="jianClick">-</span><span class="peoplenum">{{ peoplenum }}人</span><span class="changepeople1" @click="addClick">+</span></div>
    </div>
    <div class="telphone"><div class="phonetitle">联系人电话</div>
    <van-field class="phonetext" v-model="phone"  />
    </div>
    <div class="name">
        <div class="nametitle">联系人姓名</div>
        <van-field class="nametext" v-model="name"  /></div>
</div>
<div class="invoice">
<div class="free">免费赠送住宿意外险</div>
<van-switch class="freebutton" v-model="checked" />
<div class="splited">   </div>

<div class="invoicetitle">发票</div>
<div class="invoiceproblem">发票请联系房东（有疑问咨询客服）</div>

</div>
<div class="exitruler"><div>退订规则</div>
<div>取消订单。扣除全部房费作为违约金支付给房东，如提前离店，扣除
    全部剩余房费作为违约金支付给房东</div>
</div>
<div class="exitruler"><div>入住提示</div>
<div>房东确认后方可线上向房东索要入住须知，方便您安排入住；系统提供
24小时客服服务，确保您入住无忧</div>
</div>
<div class="exitruler"><div>押金提示</div>
<div>在线支付押金200元，到店后无需支付，住房押金离店后，如无需扣款，
将原方式退还</div>
</div>
<div class="submit">
<div class="submitprice">￥{{ price}}.00</div>
<div class="submittip">含押金¥200.00（可退）</div>
<van-button class="submitbutton" @click="payinto" lain type="primary">立即预定</van-button>
</div>
    </div>
    </main>
</template>

<style lang="scss" scoped>
main,.box,.content{
    width: 100%;
    height: 100%;
    background-color: #fbfbfb;
}
.homecard{
    width: 90%;
    height: 85px;
    margin: 10px auto;
    border-radius: 5px;
    box-shadow: 2px 4px  #eaeaea;
    position: relative;
    overflow: hidden;
    .cardimg{
        width: 130px;
        position: absolute;
        left: -10px;
        top: 0;
    }
    .cardtitle{
        font-size: 15px;
        position: absolute;
        left: 130px;
        top: 0;
    }
    .cardcontet{
        font-size: 13px;
        position: absolute;
        left: 130px;
        top: 30px;
    }
    .Price{
        font-size: 20px;
        position: absolute;
        left: 128px;
        bottom: 5px;
        color: #ff9b54;
        font-weight: 500;
    }
}
.datecard{
    width: 90%;
    height: 285px;
    margin: 10px auto;
    border-radius: 5px;
    box-shadow: 2px 4px  #eaeaea;
    position: relative;
    .leave{
    width: 96%;
   
    margin: 20px auto;
    .datetitle{
        float: left;
        font-size: 16px;
        font-weight: 800;
    }
    .changedate{
        float: right;
        margin-right: 18px;
        .change{
            font-size: 12px;
           position: relative;
           bottom: 3px;
           color: #b399b3;
        }
    }
}
.timebox{
    width: 96%;
    background-color: #c1dbd8;
    position: absolute;
    height: 90px;
    top: 40px;
    left: 2%;
    .timeleft{
        width: 33%;
        position: absolute;
        top: 0;
        left: 0;
        .start{
            font-size: 15px;
            position: absolute;
            left: 20px;
            top: 20px;
        }
        .timestart{
            font-size: 12px;
            position: absolute;
            left: 10px;
            top: 50px;
            color: #9999a9;
        }
     
    }
    .timeright{
        width: 33%;
        position: absolute;
        top: 0;
        right: 0;
        .end{
            font-size: 15px;
            position: absolute;
            left: 20px;
            top: 20px;
        }
        .timeend{
            font-size: 12px;
            position: absolute;
            left: 10px;
            top: 50px;
            color: #9999a9;
        }
     
    }
    .timemiddle{
        width: 70px;
        height: 25px;
        background-color: #cccccc;
        font-size: 14px;
        text-align: center;
        line-height: 25px;
        position: absolute;
        top: 30px;
        left: 120px;
    }
}
.people{
    width: 96%;
    position: absolute;
    height: 90px;
    top: 150px;
    left: 2%;
    .totalpeople{
        float: left;
        font-size: 16px;
    }
    .addpeople{
        float: right;
        position: relative;
      .changepeople1{
        font-size: 30px;
        position: absolute;
        top: -8px;
        right: 20px;
      }
      .peoplenum{
        width: 40px;
        font-size: 16px;
        position: absolute;
        top: 0;
        right: 40px;
      }
      .changepeople{
        font-size: 30px;
        position: absolute;
        top: -8px;
        right: 100px;
      }
    }
}
.telphone{
    width: 96%;
    position: absolute;
    height: 90px;
    top: 190px;
    left: 2%;
    .phonetitle{
        font-size: 16px;
line-height: 30px;
        height: 30px;
        float: left;
    }
    .phonetext{
        width: 60%;

        height: 30px;
        float: right;
        border: 1px solid;
        padding:0 10px 6px;
        box-sizing: border-box;
    }
}
.name{
    width: 96%;
    position: absolute;
    height: 90px;
    top: 240px;
    left: 2%;
    .nametitle{
        font-size: 16px;
line-height: 30px;
        height: 30px;
        float: left;
    }
    .nametext{
        width: 60%;

        height: 30px;
        float: right;
        border: 1px solid;
        padding:0 10px 6px;
        box-sizing: border-box;
    }
}
}
.invoice{
    width: 90%;
    height: 125px;
    margin: 10px auto;
    border-radius: 5px;
    box-shadow: 2px 4px  #eaeaea;
    position: relative;
    .free{
        position: absolute;
        top: 20px;
        left: 20px;
        color: #a69999;
    }
    .freebutton{
        position: absolute;
        top: 10px;
        right: 20px;
    }
    .splited{
        width: 100%;
        border: 0.1px solid #f2f2f2;
        position: absolute;
        top: 60px;  
    }
    .invoicetitle{
        font-size: 16px;
        font-weight: 800;
        position: absolute;
        top: 70px;
        left: 20px;
    }
    .invoiceproblem{
        position: absolute;
        top: 96px;
        left: 20px;
        color: #a69999;
    }
}
.exitruler{
    width: 90%;
    margin: 30px auto;
    color: #a69999;
}
.submit{
    width: 90%;
    height:0.7rem;
    margin: 10px auto;

    position: relative;
    .submitprice{
        font-size: 30px;
        position: absolute;
        left: 0;
        top: 10px;
        color: #ffcb82;
    }
    .submittip{
        color: #a69999;
        position: absolute;
        left: 5px;
        bottom: 10px;
    }
    .submitbutton{
        position: absolute;
        top:15px;
        width: 110px;
        height: 40px;
        right:10px
    }
}
</style>
    